<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //迭代器接口（Symbol.iterator）
        //需要有迭代器接口，才能用for -of枚举
        const fruits = ['apple','bear','bannan','orange']
        for(var item of fruits){
            console.log(item)
        }
        //控制一个个被枚举用next
        
        // const iterator =fruits[Symbol.iterator]() 
        // console.log(iterator.next()) //{value: 'apple', done: false}
        // console.log(iterator.next())
        // console.log(iterator.next())
        // console.log(iterator.next())
        // console.log(iterator.next())

        //重写
        fruits[Symbol.iterator]= function(){
            let i = 0
            return{
                next:() => {
                    let value = this[2*i++]
                    return{
                        value,
                        done:value ? false :true
                    }
                }
            }
        }
        const iterator =users[Symbol.iterator]()
    </script>
</body>
</html>